﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.customer.dao.impl;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.customer.dao.*;
import com.hh.bss.customer.entity.*;
import com.hh.bss.customer.service.*;
import com.hh.bss.customer.vo.query.*;
import com.hh.bss.util.*;





import static com.hh.bss.util.ObjectUtils.*;

import org.springframework.stereotype.Repository;

@Repository
public class CompanyCompetitorDaoImpl extends BaseHibernateDao<CompanyCompetitor,java.lang.Integer>  implements CompanyCompetitorDao<CompanyCompetitor,java.lang.Integer>{

	public Class getEntityClass() {
		return CompanyCompetitor.class;
	}
	public List findList(CompanyCompetitorQuery query) {
		StringBuffer sql = new StringBuffer();
		List values = new ArrayList();
		sql.append(" select * from ( ");
		sql.append(" select a.id,a.company_id companyId,c.name companyName,a.competitor_company_id competitorCompanyId,b.name competitorCompanyName,a.comment,a.create_dt createDt,a.creator from  company_competitor a  ");
		sql.append(" left join  company b on a.competitor_company_id=b.id ");
		sql.append(" left join  company c on a.company_id=c.id ");
		sql.append(" ) info ");
		if(isNotEmpty(query.getCompetitorCompanyName())) {
			sql.append(" and info.competitorCompanyName like ? ");
			values.add("%"+query.getCompetitorCompanyName()+"%");
		}
		return super.getJdbcDao().findByQuery(sql.toString(),values.toArray(), new MapObjectRowMapper());

	}
	public Page findPage(CompanyCompetitorQuery query) {
		StringBuffer sql = new StringBuffer();
		List values = new ArrayList();
		sql.append(" select * from ( ");
		sql.append(" select a.id,a.company_id companyId,c.name companyName,a.competitor_company_id competitorCompanyId,b.name competitorCompanyName,a.comment,a.create_dt createDt,a.creator from  company_competitor a  ");
		sql.append(" left join  company b on a.competitor_company_id=b.id ");
		sql.append(" left join  company c on a.company_id=c.id ");
		sql.append(" ) info where 1=1 ");
		if(isNotEmpty(query.getCompetitorCompanyName())) {
			sql.append(" and info.competitorCompanyName like ? ");
			values.add("%"+query.getCompetitorCompanyName()+"%");
		}
		if(isNotEmpty(query.getCompanyId())) {
			sql.append(" and info.companyId = ? ");
			values.add(query.getCompanyId());
		}
		return super.getJdbcDao().createPage(sql.toString(),values.toArray(), new MapObjectRowMapper(), query.getPageSize(), query.getPageNumber());
	}
	

}
